// pages/film/film.js
import http from "../../utils/http";
import Tx from "../../utils/qqmap-wx-jssdk"
var qqmapsdk = new Tx({
  key: '2ZLBZ-P7OK6-AQVS5-EA7YH-Q5IK2-DRBVZ' // 必填
});
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isHot: true,
    hotList: [],
    newList: [],
    preList: [],
    city: "",
    date:{},
  },
  formatDate(num) {
    var now = new Date();
    var nowTime = now.getTime();
    var oneDayTime = 24 * 60 * 60 * 1000;
    var ShowTime = nowTime + num * oneDayTime;
    var myDate = new Date(ShowTime);
    var m = myDate.getMonth() + 1; //月
    var d = myDate.getDate(); //日
    return m+"月"+d+"日"
  },
  hotMovie() {
    this.setData({
      isHot: true,
    })
  },
  newMovie() {
    this.setData({
      isHot: false,
    })
    http.get("/api/douban/movie/coming_soon").then(res => {
      // console.log(res)
      this.setData({
        newList: res.data.data.list,
      })
    })
    http.get("/api/douban/movie/selectPreview").then(res => {
      // console.log(res)
      this.setData({
        preList: res.data.data,
      })
    })
    var arr = [];
    for(var i=0;i<7;i++){
      var day = this.formatDate(i);
      arr.push(day)
    }
    // console.log(arr)
    this.setData({
      date:arr,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    http.get("/api/douban/movie/in_theaters").then(res => {
      // console.log(res)
      this.setData({
        hotList: res.data.data.list
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this;
    wx.getLocation({
      success(res) {
        // console.log(res)
        qqmapsdk.reverseGeocoder({
          location: `${res.latitude},${res.longitude}`,
          success(val) {
            // console.log(val)
            _this.setData({
              city: val.result.address_component.city,
            })
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})